package com.artPreter.controller.pc;

import com.artPreter.pojo.*;
import com.artPreter.service.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import static com.artPreter.utils.PageUtils.getPageList;

@Controller
public class OnlineArtworkController {

    @Autowired
    private IArtworkService artWorkService;
    @Autowired
    private IArtTypeService artTypeService;
    @Autowired
    private IDepartContentSectionService departContentSectionService;
    @Autowired
    private ISystemConfigService systemConfigService;




    /**
     *
     * @param id 艺术品id
     * @param
     * @param model
     * @return
     */
    @GetMapping("/online/artwork/detail")
    public String onlineArtworkDetail(Integer id, Model model) {
        // 系统设置
        HashMap systemConfig = systemConfigService.getSystemConfig();
        model.addAttribute("systemConfig",systemConfig);
        // 头部菜单
        List<DepartContentSection> menuList = departContentSectionService.getMenuList();
        model.addAttribute("menus",menuList);
        for (int i = 0; i < menuList.size(); i++) {
            System.out.println(menuList.get(i).getContent());
            if(menuList.get(i).getContent().equals("/artwork/online")){
                menuList.get(i).setIsActice(1);
                model.addAttribute("backName",menuList.get(i).getName());
                model.addAttribute("backContent",menuList.get(i).getContent());
            }
        }


        // 首页显示艺术类型
        List<ArtType> artTypes = artTypeService.getList();
        model.addAttribute("artTypes",artTypes);

        Artwork artwork = artWorkService.getArtWorkById(id);



        if(artwork!=null&&artwork.getId()!=null){
            if(artwork.getArtwoktType()!=null) {
                for (int i = 0; i < artTypes.size(); i++) {
                    if(artTypes.get(i).getTypeId().equals(artwork.getArtwoktType())){
                        artwork.setArtTypeName(artTypes.get(i).getName());
                    }
                }
            }
            model.addAttribute("artwork",artwork);
            return "pc/index/online_detail";
        } else {
            return "redirect:/";
        }
    }
}
